package tsing.javase.thread.pool;

import java.util.concurrent.*;

public class TestThreadPool {

    static ThreadLocal<Object> threadLocal = new ThreadLocal<>();


    public static void main(String[] args) {
        new TestThreadPool().testThreadPool();
    }

    public void testThreadPool(){

        ThreadPoolExecutor pool1 = (ThreadPoolExecutor) Executors.newCachedThreadPool();

        ThreadPoolExecutor poolOne = (ThreadPoolExecutor)Executors.newFixedThreadPool(1);




        pool1.execute(()-> System.out.println("快捷线程中的线程！"));



        ThreadPoolExecutor pool2 = MyPool.getInstance().getThreadPool();
        pool2.execute(()->{
            System.out.println("pool2 普通线程池中的线程");

            try {
                Thread.sleep(30*1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });


        System.out.println("pool2 poolSize:" + pool2.getPoolSize());


        System.out.println("pool2 corePoolSize:" + pool2.getCorePoolSize());


        System.out.println("pool2 largestPoolSize:" + pool2.getLargestPoolSize());


        System.out.println("pool2 maximumPoolSize:" + pool2.getMaximumPoolSize());

        ScheduledThreadPoolExecutor pool3 = MyPool.getInstance().getScheduledPool();

        pool3.scheduleAtFixedRate(()-> System.out.println("计划任务线程池中的线程！"),0,500, TimeUnit.MILLISECONDS);

    }
}
